scriptSupport.addInit(function() {
	var doc = Doc(document);
	doc.contentPanel = new ContentPanel(doc);
	StatusDisplay.getInstance();
});

function ContentPanel(doc) {
	this.doc = doc;
	var el = Dom(this.doc.doc.body).getFirstChildByClassName("contentPanel");
	if (!el) {
		el = this.doc.doc.createElement("div");
		while (this.doc.doc.body.childNodes.length > 0)
			el.appendChild(this.doc.doc.body.childNodes[0]);
		el.className = "contentPanel";
		this.doc.doc.body.appendChild(el);
		el.id = this.doc.doc.body.id;
	}
	ContentPanel._super.call(this, el);
	this.cleanup();
}
Object.extend("ContentPanel", "E.Dom");

ContentPanel.prototype.merge = function(el, restoreSelection) {
	if (!el || !el.hasChildNodes())
	  return;
	var d = Dom(el);
	var sel = this.doc.selectionSupport;
	var selId;
	if (restoreSelection && sel && sel.current)
		selId = sel.current.entityView.dom.element.id;
	if (typeof(EntityView) == "function")
		EntityView.entityViews = null;
	d.cleanup();
	d.mergeInto(this.element);
	this.element.className = "contentPanel";
	var dyns = this.element.getElementsByTagName("iframe");
	for (var i = 0; i < dyns.length; ++i) {
		dyns[i].contentWindow.location.reload();
	}
	var dyns = this.element.getElementsByTagName("iframe");
	for (var i = 0; i < dyns.length; ++i)
		dyns[i].contentWindow.location.reload();
	this.doc.applyEditFeatures && this.doc.applyEditFeatures();
	if (selId)
		sel.select(Dom(selId).getEntityView());
}

ContentPanel.prototype.getViewUri = function() {
	return this.doc.getViewUri();
}

function StatusDisplay(doc) {
	this.doc = doc;
	this.dom = this.doc.createElement("div");
	this.fadeSupport = new FadeSupport(this.dom);
	this.fadeSupport.hide();
	this.doc.body.appendChild(this.dom);
}

StatusDisplay.getInstance = function() {
	if (!document.statusDisplay)
		document.statusDisplay = new StatusDisplay(document);
	return document.statusDisplay;
}

StatusDisplay.prototype.show = function(text, url, fade) {
	this._show(text, "status_msg", url, fade);
}

StatusDisplay.prototype.showError = function(text, url, fade) {
	this._show(text, "status_error", url, fade);
}

StatusDisplay.prototype._show = function(text, className, url, fade) {
	this._clearTimer();
	if (url)
		this.dom.innerHTML = "<a href=\"" + BasePath.get() + url + "\">" + text + "</a>";
	else
		this.dom.innerHTML = text;
	this.dom.className = className;
	this.fadeSupport.show();
	if (fade) {
		this.timerId = window.setTimeout(function(display) {
			display.hide();
		}, 1000, this);
	}
}

StatusDisplay.prototype._clearTimer = function() {
	if (this.timerId) {
		var id = this.timerId;
		this.timerId = null;
		window.clearTimeout(id);
	}
}

StatusDisplay.prototype.hide = function() {
	this._clearTimer();
	this.fadeSupport.fadeOut(true);
}
